package com.bdqn.t382.lx;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Lx01 {
    public static void main(String[] args) {
        try {
            Class<?> aClass = Class.forName("com.bdqn.t382.pojo.Person");
            String simpleName = aClass.getSimpleName(); // 得到类名
            System.out.println("类名：" + simpleName);
            System.out.println("==================================");
            int modifier = aClass.getModifiers(); // 获取 Person 类的实例的访问修饰符
            System.out.println(simpleName + " 类的修饰符：");
            if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC)
                System.out.println("访问修饰符是：public");
            else
                System.out.println("访问修饰符是：default(package)");
            if ((modifier & Modifier.FINAL) == Modifier.FINAL)
                System.out.println("这个类是 final 的");
            if ((modifier & Modifier.ABSTRACT) == Modifier.ABSTRACT)
                System.out.println("这是一个抽象类");
            if ((modifier & Modifier.INTERFACE) == Modifier.INTERFACE)
                System.out.println("这是一个接口");
            System.out.println("===================================");
            Class superClass = aClass.getSuperclass(); // 父类
            System.out.println(simpleName + "类的超类是"
                    + superClass.getName());
            System.out.println("===================================");
            Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
            System.out.println("构造方法:\t");
            for (Constructor<?> declaredConstructor : declaredConstructors) {

                System.out.println(declaredConstructor);
            }
            System.out.println("===================================");
            Field[] fields = aClass.getDeclaredFields();
            System.out.println("属性：");
            for (Field field : fields) {
                System.out.println(field);
            }
            System.out.println("===================================");
            Method[] methods = aClass.getDeclaredMethods();
            System.out.println("方法：");
            for (Method method : methods) {
                System.out.println(method);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
